package pl.lodz.p.tewi;

import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.math.*;



public class ElGamalFrame extends JInternalFrame implements InternalFrameListener
{
    private ElGamal elgamal=new ElGamal();
    private boolean reczna_edycja_klucza=false;
    private byte tekstJawny[];
    private BigInteger szyfrogram[];
    private BigInteger deszyfrogram[];
    private File plikKluczaPub,plikKluczaSec, plikOdczytuTekstu, plikzapisuTekstu, plikOdczytuszyfr, plikzapisuSzyfr;
 
    class ElGamalSecFilter extends javax.swing.filechooser.FileFilter 
    {
        
        String ext;
        
        public ElGamalSecFilter ()
        {
            ext=".ElGamalSecKey";
        }
       
        @Override
        public boolean accept(File file)
        {  if (file.isDirectory()) return true;
    
            return file.getName().endsWith(ext);
        }
        
        @Override
        public String getDescription()
        {
            return "Plik klucza prywatnego algorytmu ElGamal";
        }
    }
    
    class ElGamalPubFilter extends javax.swing.filechooser.FileFilter 
    {
        
        String ext;
        
        public ElGamalPubFilter ()
        {
            ext=".ElGamalPubKey";
        }
       
        @Override
        public boolean accept(File file)
        {  if (file.isDirectory()) return true;
    
            return file.getName().endsWith(ext);
        }
        
        @Override
        public String getDescription()
        {
            return "Plik klucza publicznego algorytmu ElGamal";
        }
    }
    
   

      class dl implements DocumentListener
        { 	public void insertUpdate(DocumentEvent e){reczna_edycja_klucza=true;}
                public void removeUpdate(DocumentEvent e){reczna_edycja_klucza=true;}
                public void changedUpdate(DocumentEvent e){reczna_edycja_klucza=true;}
        }
    
    public ElGamalFrame(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) 
    {
       super(title, resizable, closable, maximizable, iconifiable);
        
       
        this.addInternalFrameListener(this);
        initComponents();
        jTextField3.setText(elgamal.g.toString(16));
        jTextField8.setText(elgamal.h.toString(16));
        jTextField9.setText(elgamal.a.toString(16));
        jTextField10.setText(elgamal.N.toString(16));
        jTextField3.getDocument().addDocumentListener(new dl());
        jTextField8.getDocument().addDocumentListener(new dl());
        jTextField9.getDocument().addDocumentListener(new dl());
        jTextField10.getDocument().addDocumentListener(new dl());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        generuj_klucz = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        wczytaj_klucz = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        zapisz_klucz = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        wczytaj_plik_tekst_jawny = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        wczytaj_plik_szyfrogram = new javax.swing.JButton();
        zapisz_plik_szyfrogram = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        zapisz_plik_tekst_jawny = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        szyfruj = new javax.swing.JButton();
        deszyfruj = new javax.swing.JButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jTextField2 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(800, 600));
        setRequestFocusEnabled(false);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e1) {
            e1.printStackTrace();
        }

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Klucz"));
        jPanel1.setPreferredSize(new java.awt.Dimension(800, 200));

        jLabel3.setText("Klucz Publiczny: g");

        jTextField3.setToolTipText("");
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        generuj_klucz.setText("Generuj klucze");
        generuj_klucz.setName("generuj_klucz"); // NOI18N
        generuj_klucz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generuj_kluczActionPerformed(evt);
            }
        });

        jLabel4.setText("Wygeneruj wartości kluczy");

        jTextField4.setText("Nazwa pliku kluczy");

        jLabel7.setText("Wczytaj klucze z pliku");

        wczytaj_klucz.setText("Wczytaj");
        wczytaj_klucz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wczytaj_kluczActionPerformed(evt);
            }
        });

        jLabel8.setText("Zapisz klucze do pliku");

        jTextField7.setText("Nazwa pliku kluczy");

        zapisz_klucz.setText("Zapisz");
        zapisz_klucz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zapisz_kluczActionPerformed(evt);
            }
        });

        jLabel9.setText("Klucz Publiczny: h");

        jLabel10.setText("Klucz Prywatny: a");

        jLabel11.setText("MOD N");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(wczytaj_klucz)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zapisz_klucz))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 660, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 12, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField8, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
                            .addComponent(jTextField9)
                            .addComponent(jTextField10)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(generuj_klucz, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {wczytaj_klucz, zapisz_klucz});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextField4, jTextField7});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel3, jLabel9});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextField8, jTextField9});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(generuj_klucz))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(wczytaj_klucz)
                    .addComponent(jLabel8)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zapisz_klucz))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Szyfrowanie / Deszyfrowanie"));
        jPanel2.setPreferredSize(new java.awt.Dimension(800, 400));

        jTextField1.setText("Nazwa pliku z tekstem jawnym");
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Otwórz plik zawierający tekst jawny");

        wczytaj_plik_tekst_jawny.setText("Otwórz");
        wczytaj_plik_tekst_jawny.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wczytaj_plik_tekst_jawnyActionPerformed(evt);
            }
        });

        jLabel2.setText("Otwórz plik zawierający szyfrogram");

        wczytaj_plik_szyfrogram.setText("Otwórz");
        wczytaj_plik_szyfrogram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wczytaj_plik_szyfrogramActionPerformed(evt);
            }
        });

        zapisz_plik_szyfrogram.setText("Zapisz");
        zapisz_plik_szyfrogram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zapisz_plik_szyfrogramActionPerformed(evt);
            }
        });

        jLabel5.setText("Zapisz plik zawierający tekst jawny");

        jTextField5.setText("Nazwa pliku z tekstem jawnym");

        jTextField6.setText("Nazwa pliku z szyfrogramem");

        jLabel6.setText("Zapisz plik zawierający szyfrogram");

        zapisz_plik_tekst_jawny.setText("Zapisz");
        zapisz_plik_tekst_jawny.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zapisz_plik_tekst_jawnyActionPerformed(evt);
            }
        });

        jTextArea2.setColumns(20);
        jTextArea2.setLineWrap(true);
        jTextArea2.setRows(5);
        jTextArea2.setText("Tu podaj szyfrogram");
        jScrollPane2.setViewportView(jTextArea2);

        szyfruj.setText("Szyfruj->");
        szyfruj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                szyfrujActionPerformed(evt);
            }
        });

        deszyfruj.setText("<-Deszyfruj");
        deszyfruj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deszyfrujActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Plik");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Okno");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jTextField2.setText("Nazwa pliku z szyfrogramem");

        jTextArea1.setColumns(20);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("Tu podaj tekst jawny");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(wczytaj_plik_tekst_jawny))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zapisz_plik_tekst_jawny, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2)))
                    .addComponent(szyfruj, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deszyfruj, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zapisz_plik_szyfrogram, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(wczytaj_plik_szyfrogram, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {wczytaj_plik_szyfrogram, wczytaj_plik_tekst_jawny, zapisz_plik_szyfrogram, zapisz_plik_tekst_jawny});

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(wczytaj_plik_tekst_jawny)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(wczytaj_plik_szyfrogram))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addGap(1, 1, 1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zapisz_plik_tekst_jawny)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zapisz_plik_szyfrogram))
                .addGap(93, 93, 93))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(109, 109, 109)
                .addComponent(szyfruj)
                .addGap(9, 9, 9)
                .addComponent(deszyfruj)
                .addGap(26, 26, 26)
                .addComponent(jRadioButton1)
                .addGap(1, 1, 1)
                .addComponent(jRadioButton2)
                .addGap(68, 68, 68))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 825, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 825, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void wczytaj_plik_tekst_jawnyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wczytaj_plik_tekst_jawnyActionPerformed
    JFileChooser fch = new JFileChooser();
    int wybor =fch.showOpenDialog(this);
    if (wybor == JFileChooser.APPROVE_OPTION) 
    {   String pom=fch.getSelectedFile().getPath();
        plikOdczytuTekstu=new File(pom);
        jTextField1.setText(pom);
       try
        {tekstJawny=Auxx.wczytajZPliku(pom);
         jTextArea1.setText(new String(tekstJawny));
        }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };
    }

    }//GEN-LAST:event_wczytaj_plik_tekst_jawnyActionPerformed

    private void wczytaj_plik_szyfrogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wczytaj_plik_szyfrogramActionPerformed
    JFileChooser fch = new JFileChooser();
    int wybor =fch.showOpenDialog(this);
    if (wybor == JFileChooser.APPROVE_OPTION) 
    {   String pom=fch.getSelectedFile().getPath();
        plikOdczytuszyfr=new File(pom);
        jTextField2.setText(pom);
        try
        {   szyfrogram=Auxx.wczytajZPlikuTabliceBigInt(pom);
            String tekst=""; 
            for (int i=0;i<szyfrogram.length;i++) 
                tekst+=Auxx.bytesToHex(szyfrogram[i].toString().getBytes());
            jTextArea2.setText(tekst);
        }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };

    }
    }//GEN-LAST:event_wczytaj_plik_szyfrogramActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void szyfrujActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_szyfrujActionPerformed
      /*sprawzamy czy hex osobno e,d,N new String(,16)
       * sprawdzamy czy długości się zgadzają e->32 znaki, N, d ->64 znaki
       * ustawiamy w klasie e,d,n*/
        try{
           if(reczna_edycja_klucza)
            {
                if(jTextField3.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za krótka.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField3.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za długa.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za krótka.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za długa.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField10.getText().length()<elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za krótka.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");
                if(jTextField10.getText().length()>elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za długa.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");

                elgamal.g= new BigInteger(jTextField3.getText(),16);
                elgamal.a= new BigInteger(jTextField9.getText(),16);
                elgamal.N= new BigInteger(jTextField10.getText(),16);
                elgamal.h=elgamal.g.modPow(elgamal.a,elgamal.N);
                BigInteger h=new BigInteger(jTextField8.getText(),16);
                if (!elgamal.h.equals(h))
                    {JOptionPane.showMessageDialog(null, "Wartość h nie zgadza się z wartościami g, a oraz N!\nzostała obliczona poprawna wartość h.", "Problem z kluczem publicznym", JOptionPane.ERROR_MESSAGE);
                    jTextField8.setText(elgamal.h.toString(16));
                    }
                reczna_edycja_klucza=false;
            } 
           
             if(jRadioButton1.isSelected())//plik
             {  if(tekstJawny!=null) szyfrogram=elgamal.encrypt(tekstJawny);
                else throw new Exception("Wybierz plik zawierający tekst jawny!");
                 
                String wynik="";
                for(int i=0;i<szyfrogram.length;i++)wynik+=Auxx.bigIntToString(szyfrogram[i]);
                jTextArea2.setText(Auxx.bytesToHex(wynik.getBytes()));
             }
             else jTextArea2.setText(Auxx.bytesToHex(elgamal.encryptFromStringToString(jTextArea1.getText()).getBytes())); 
             
           } catch(ElGamal.ElGamalKeyException e){JOptionPane.showMessageDialog(null, e.getMessage(), "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
             catch(NumberFormatException  e1){JOptionPane.showMessageDialog(null, "Wartość klucza musi być podana w systemie szesnastkowym!", "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
             catch(Exception e2){JOptionPane.showMessageDialog(null, e2.getMessage(), "Wybierz plik", JOptionPane.ERROR_MESSAGE); }
              
            
    }//GEN-LAST:event_szyfrujActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void generuj_kluczActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generuj_kluczActionPerformed
        elgamal.generateKey();
        jTextField3.setText(elgamal.g.toString(16));
        jTextField8.setText(elgamal.h.toString(16));
        jTextField9.setText(elgamal.a.toString(16));
        jTextField10.setText(elgamal.N.toString(16));
        reczna_edycja_klucza=false;
        
    }//GEN-LAST:event_generuj_kluczActionPerformed

    private void wczytaj_kluczActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wczytaj_kluczActionPerformed
     try{
        JFileChooser fch = new JFileChooser();
        fch.setDialogTitle("Podaj nazwę pliku klucza prywatnego");
        fch.setFileFilter(new ElGamalSecFilter()); 
        int wybor =fch.showOpenDialog(this);
        if (wybor == JFileChooser.APPROVE_OPTION) 
        {   String pom=fch.getSelectedFile().getPath();
            plikKluczaSec=new File(pom);
            jTextField4.setText(pom);
            try
            {  String tab[]=(new String(Auxx.wczytajZPliku(pom))).split("\n");   
                jTextField9.setText(tab[0]);
                jTextField10.setText(tab[1]);
            }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };
        }
        fch.setDialogTitle("Podaj nazwę pliku klucza publicznego");
        fch.setFileFilter(new ElGamalPubFilter()); 
        wybor =fch.showOpenDialog(this);
        if (wybor == JFileChooser.APPROVE_OPTION) 
        {   String pom=fch.getSelectedFile().getPath();
            plikKluczaPub=new File(pom);
            jTextField4.setText(pom);
            try
            {  String tab[]=(new String(Auxx.wczytajZPliku(pom))).split("\n");   
                jTextField3.setText(tab[0]);
                jTextField8.setText(tab[1]);
                jTextField10.setText(tab[2]);
            }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };
        }
                 if(jTextField3.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za krótka.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField3.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za długa.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za krótka.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za długa.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField10.getText().length()<elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za krótka.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");
                if(jTextField10.getText().length()>elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za długa.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");

                elgamal.g= new BigInteger(jTextField3.getText(),16);
                elgamal.a= new BigInteger(jTextField9.getText(),16);
                elgamal.N= new BigInteger(jTextField10.getText(),16);
                elgamal.h=elgamal.g.modPow(elgamal.a,elgamal.N);
                BigInteger h=new BigInteger(jTextField8.getText(),16);
                if (!elgamal.h.equals(h))
                    {JOptionPane.showMessageDialog(null, "Wartość h nie zgadza się z wartościami g, a oraz N!\nzostała obliczona poprawna wartość h.", "Problem z kluczem publicznym", JOptionPane.ERROR_MESSAGE);
                    jTextField8.setText(elgamal.h.toString(16));
                    }
                reczna_edycja_klucza=false;
     }catch(ElGamal.ElGamalKeyException e){JOptionPane.showMessageDialog(null, e.getMessage(), "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
      catch(NumberFormatException  e1){JOptionPane.showMessageDialog(null, "Wartość klucza musi być podana w systemie szesnastkowym!", "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }

    }//GEN-LAST:event_wczytaj_kluczActionPerformed

    private void zapisz_plik_szyfrogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zapisz_plik_szyfrogramActionPerformed
       JFileChooser fch = new JFileChooser();
       int wybor =fch.showSaveDialog(this);
       if (wybor == JFileChooser.APPROVE_OPTION) 
    {   String pom=fch.getSelectedFile().getPath();
        plikzapisuSzyfr=new File(pom);
        jTextField6.setText(pom);
        try{ if(jRadioButton1.isSelected())//plik
             Auxx.zapiszDoPlikuTabliceBigIntNewLine(szyfrogram,pom);
             else Auxx.zapiszDoPliku(Auxx.hexToBytes(jTextArea2.getText()), pom);
            }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z zapisem do pliku"+pom, "Problem z zapisem do pliku", JOptionPane.ERROR_MESSAGE); };         

    }
    }//GEN-LAST:event_zapisz_plik_szyfrogramActionPerformed

    private void zapisz_plik_tekst_jawnyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zapisz_plik_tekst_jawnyActionPerformed
       JFileChooser fch = new JFileChooser();
       int wybor =fch.showSaveDialog(this);
       if (wybor == JFileChooser.APPROVE_OPTION) 
    {   String pom=fch.getSelectedFile().getPath();
        plikzapisuTekstu=new File(pom);
        jTextField5.setText(pom);
        try{ 
                if(jRadioButton1.isSelected())//plik
                if(deszyfrogram.length>0)Auxx.zapiszDoPlikuTabliceBigInt(deszyfrogram, pom);
                else if(tekstJawny.length>0) Auxx.zapiszDoPliku(tekstJawny, pom);
             else
            Auxx.zapiszDoPliku(jTextArea1.getText().getBytes(), pom);
           }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z zapisem do pliku"+pom, "Problem z zapisem do pliku", JOptionPane.ERROR_MESSAGE); };         

    }
    }//GEN-LAST:event_zapisz_plik_tekst_jawnyActionPerformed

    private void deszyfrujActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deszyfrujActionPerformed
      try{
            if(reczna_edycja_klucza)
            {
                 if(jTextField3.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za krótka.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField3.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za długa.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za krótka.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za długa.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField10.getText().length()<elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za krótka.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");
                if(jTextField10.getText().length()>elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za długa.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");

                elgamal.g= new BigInteger(jTextField3.getText(),16);
                elgamal.a= new BigInteger(jTextField9.getText(),16);
                elgamal.N= new BigInteger(jTextField10.getText(),16);
                elgamal.h=elgamal.g.modPow(elgamal.a,elgamal.N);
                BigInteger h=new BigInteger(jTextField8.getText(),16);
                if (!elgamal.h.equals(h))
                    {JOptionPane.showMessageDialog(null, "Wartość h nie zgadza się z wartościami g, a oraz N!\nzostała obliczona poprawna wartość h.", "Problem z kluczem publicznym", JOptionPane.ERROR_MESSAGE);
                    jTextField8.setText(elgamal.h.toString(16));
                    }
                reczna_edycja_klucza=false;
            } 
          
             if(jRadioButton1.isSelected())//plik
             {deszyfrogram=elgamal.decryptToBigInt(szyfrogram);
              String wynik="";
              for(int i=0;i<deszyfrogram.length;i++)wynik+=Auxx.bigIntToString(deszyfrogram[i]);
              jTextArea1.setText(wynik);
             }
             else  
             {String spom=new String(Auxx.hexToBytes(jTextArea2.getText()));
                     jTextArea1.setText(elgamal.decryptFromStringToString(spom));
             }
           } catch(ElGamal.ElGamalKeyException e){JOptionPane.showMessageDialog(null, e.getMessage(), "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
             catch(NumberFormatException  e1){JOptionPane.showMessageDialog(null, "Wartość klucza musi być podana w systemie szesnastkowym!", "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
     
    }//GEN-LAST:event_deszyfrujActionPerformed

    private void zapisz_kluczActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zapisz_kluczActionPerformed
      try{ 
           if(reczna_edycja_klucza)
            {
                if(jTextField3.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za krótka.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField3.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość g jest za długa.\nWynosi "+ jTextField3.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()<elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za krótka.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField9.getText().length()>elgamal.ilZnHex)throw elgamal.new ElGamalKeyException("Podana wartość a jest za długa.\nWynosi "+ jTextField9.getText().length()+" .\nMusi wynosić "+ elgamal.ilZnHex+" znaki w systemie szesnastkowym.");
                if(jTextField10.getText().length()<elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za krótka.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");
                if(jTextField10.getText().length()>elgamal.ilZnHex+1)throw elgamal.new ElGamalKeyException("Podana wartość N jest za długa.\nWynosi "+ jTextField10.getText().length()+" .\nMusi wynosić "+ (elgamal.ilZnHex+1)+" znaków w systemie szesnastkowym.");

                elgamal.g= new BigInteger(jTextField3.getText(),16);
                elgamal.a= new BigInteger(jTextField9.getText(),16);
                elgamal.N= new BigInteger(jTextField10.getText(),16);
                elgamal.h=elgamal.g.modPow(elgamal.a,elgamal.N);
                BigInteger h=new BigInteger(jTextField8.getText(),16);
                if (!elgamal.h.equals(h))
                    {JOptionPane.showMessageDialog(null, "Wartość h nie zgadza się z wartościami g, a oraz N!\nzostała obliczona poprawna wartość h.", "Problem z kluczem publicznym", JOptionPane.ERROR_MESSAGE);
                    jTextField8.setText(elgamal.h.toString(16));
                    }
                reczna_edycja_klucza=false;
            } 
         
          JFileChooser fch = new JFileChooser();
          fch.setDialogTitle("Podaj nazwę pliku klucza prywatnego");
          fch.setFileFilter(new ElGamalSecFilter());
          int wybor =fch.showSaveDialog(this);
            if (wybor == JFileChooser.APPROVE_OPTION) 
            {   String pom=fch.getSelectedFile().getPath();
                if (pom.lastIndexOf('.')==-1)pom+=".ElGamalSecKey";
                plikKluczaSec=new File(pom);
                jTextField7.setText(pom);
               try
                { String spom=jTextField9.getText()+'\n'+jTextField10.getText();
                  Auxx.zapiszDoPliku(spom.getBytes(), pom);
                }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };
            }
          fch.setDialogTitle("Podaj nazwę pliku klucza publicznego");
          fch.setFileFilter(new ElGamalPubFilter());
          wybor =fch.showSaveDialog(this);
            if (wybor == JFileChooser.APPROVE_OPTION) 
            {   String pom=fch.getSelectedFile().getPath();
                if (pom.lastIndexOf('.')==-1)pom+=".ElGamalPubKey";
                plikKluczaPub=new File(pom);
                jTextField7.setText(pom);
               try
                { String spom=jTextField3.getText()+'\n'+jTextField8.getText()+'\n'+jTextField10.getText();
                  Auxx.zapiszDoPliku(spom.getBytes(), pom);
                }catch(Exception e){JOptionPane.showMessageDialog(null, "Problem z otworzeniem pliku"+pom, "Problem z otworzeniem pliku", JOptionPane.ERROR_MESSAGE); };
            }
      }catch(ElGamal.ElGamalKeyException e){JOptionPane.showMessageDialog(null, e.getMessage(), "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }
       catch(NumberFormatException  e1){JOptionPane.showMessageDialog(null, "Wartość klucza musi być podana w systemie szesnastkowym!", "Problem z kluczem", JOptionPane.ERROR_MESSAGE); }

    }//GEN-LAST:event_zapisz_kluczActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2ActionPerformed

        
    @Override
    public void internalFrameActivated(InternalFrameEvent e) {};
    
    @Override
    public void internalFrameClosed(InternalFrameEvent e) {};
    
    @Override
    public void internalFrameClosing(InternalFrameEvent e) 
    {
       this.dispose();
        
    };
    
    @Override
    public void internalFrameDeactivated(InternalFrameEvent e) {};
    
    @Override
    public void internalFrameDeiconified(InternalFrameEvent e) {};
    
    @Override
    public void internalFrameIconified(InternalFrameEvent e) {};
    
    @Override
    public void	internalFrameOpened(InternalFrameEvent e) {};            
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton deszyfruj;
    private javax.swing.JButton generuj_klucz;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JButton szyfruj;
    private javax.swing.JButton wczytaj_klucz;
    private javax.swing.JButton wczytaj_plik_szyfrogram;
    private javax.swing.JButton wczytaj_plik_tekst_jawny;
    private javax.swing.JButton zapisz_klucz;
    private javax.swing.JButton zapisz_plik_szyfrogram;
    private javax.swing.JButton zapisz_plik_tekst_jawny;
    // End of variables declaration//GEN-END:variables
}
